/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package com.plian.system.service.pm.realproperty.impl;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.read.listener.PageReadListener;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.fill.FillConfig;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.plian.Tools.*;
import com.plian.Tools.pagedata.PageData;
import com.plian.system.bean.pm.EstateInfoExcelBean;
import com.plian.system.bean.pm.HouseInfoExcelBean;
import com.plian.system.bean.pm.LandInfoExcelBean;
import com.plian.system.cache.UserCache;
import com.plian.system.config.exception.MyRuntimeException;
import com.plian.system.constant.baseinfo.ValueSetConstant;
import com.plian.system.constant.sys.FormStatusConstant;
import com.plian.system.constant.sys.FormTypeConstant;
import com.plian.system.constant.yth.YthConstant;
import com.plian.system.dao.sys.orgzation.OrgzationDao;
import com.plian.system.entity.pm.realproperty.RealProperty;
import com.plian.system.entity.pm.realproperty.RealPropertyQuo;
import com.plian.system.entity.sys.ApprovalMessage;
import com.plian.system.entity.sys.Org;
import com.plian.system.enumeratea.LandStatus;
import com.plian.system.excel.ImportExcelUtil;
import com.plian.system.excel.ImportResult;
import com.plian.system.mapper.pm.realproperty.RealPropertyMapper;
import com.plian.system.mapper.yth.realproperty.HouseMapper;
import com.plian.system.mapper.yth.realproperty.LandMapper;
import com.plian.system.model.ListResult;
import com.plian.system.model.ObjResult;
import com.plian.system.mybatis.base.BaseFlowService;
import com.plian.system.mybatis.base.BaseServiceImpl;
import com.plian.system.service.bt.baseinfo.BaseInfoService;
import com.plian.system.service.pm.realproperty.IRealPropertyLatestService;
import com.plian.system.service.pm.realproperty.IRealPropertyQuoService;
import com.plian.system.service.pm.realproperty.IRealPropertyService;
import com.plian.system.service.sys.code.IFormCodeService;
import com.plian.system.service.sys.file.FileService;
import com.plian.system.service.sys.message.IApprovalMessageService;
import com.plian.system.service.sys.orgzation.IOrgService;
import com.plian.system.service.sys.orgzation.OrgzationService;
import com.plian.system.service.wf.FormWorkflowService;
import com.plian.system.vo.pm.realproperty.RealPropertyFormVO;
import com.plian.system.vo.pm.realproperty.RealPropertyVO;
import com.plian.system.vo.pm.realproperty.RealPropertyYearInfoVO;
import com.plian.system.vo.yth.YthResult;
import com.plian.system.wrapper.pm.realproperty.RealPropertyWrapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.util.*;
import java.util.concurrent.Future;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static com.plian.system.constant.baseinfo.ValueSetConstant.BUILDING_STRUCTURE;
import static com.plian.system.constant.baseinfo.ValueSetConstant.LAND_TYPE;
import static com.plian.system.constant.sys.FormStatusConstant.UNREVIEWED;

/**
 * 不动产登记信息表 服务实现类
 *
 * @author BladeX
 * @since 2021-06-01
 */
@Slf4j
@Service
@AllArgsConstructor
public class RealPropertyServiceImpl extends BaseServiceImpl<RealPropertyMapper, RealProperty> implements IRealPropertyService, BaseFlowService {

    private FileService fileService;

    private FormWorkflowService formWorkflowService;

    private IFormCodeService formCodeService;

    private BaseInfoService baseInfoService;

    private OrgzationService orgzationService;

    private IRealPropertyQuoService realPropertyQuoService;

    private IRealPropertyLatestService realPropertyLatestService;

    private RealPropertyMapper realPropertyMapper;

    private RealPropertyWrapper realPropertyWrapper;

    private OrgzationDao orgzationDao;

    private IOrgService orgService;

    private IApprovalMessageService approvalMessageService;

    private LandMapper landMapper;

    private HouseMapper houseMapper;

    @Override
    public boolean saveOrUpdate(RealProperty realProperty) {
        boolean flag = false;
        if (realProperty.getId() == null){
            flag = true;
            realProperty.setCode(formCodeService.getCode(FormTypeConstant.PM_REAl_PROPERTY));
            realProperty.setFormType(String.valueOf(FormTypeConstant.PM_REAl_PROPERTY));
            realProperty.setVersion(1);
        }

        boolean result = super.saveOrUpdate(realProperty);
        if (flag){
            fileService.saveAll(String.valueOf(realProperty.getId()), realProperty.getDocList());
        }else {
            fileService.edit(String.valueOf(realProperty.getId()), realProperty.getDocList());
        }

        return result;
    }

    @Override
    public boolean deleteLogic(List<Long> ids) {
        for (Long id : ids) {
            RealProperty realProperty = getById(id);
            if (realProperty == null) {
                return false;
            } else if (realProperty.getStatus() != null &&
                    (realProperty.getStatus() != FormStatusConstant.STASH && realProperty.getStatus() != UNREVIEWED)) {
                return false;
            }
            formWorkflowService.deleteProcessInstance(String.valueOf(id));
        }
        boolean result = super.deleteLogic(ids);
        return result;
    }

    @Override
    public HashMap<String,Object> commit(String id) {
        handleStatus(Long.valueOf(id), FormStatusConstant.FLOW, "提交");

        //将需要提交的流程变量返回，用于工作流侧
        return new HashMap<String,Object>();
    }

    @Override
    public Boolean finish(String id) {
        /**
         * 设置审批人和审批时间
         */
        RealProperty realProperty = getById(id);
        realProperty.setApprovedUser(TokenUtil.getTokenUserId());
        Date now = DateUtil.now();
        realProperty.setApprovedTime(now);
        realProperty.setIsLatest(2);
        realProperty.setVersion(1);
        realProperty.setInitialId(Long.valueOf(id));
        realProperty.setIsEntrust(1);
        realProperty.setLandStatus(LandStatus.ADJUSTABLE.getStatus());
        updateById(realProperty);

        return handleStatus(Long.valueOf(id), FormStatusConstant.FINISH, "审批完成");
    }

    @Override
    public Boolean reject(String id, int formState, String comment) {
        return handleStatus(Long.valueOf(id), formState, comment);
    }


    @Override
    public List<PageData> findByIds(List<String> formIds) {
        LambdaQueryWrapper<RealProperty> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(RealProperty::getId, Func.toLongList(StringUtils.join(formIds, StringPool.COMMA)));
        List<RealProperty> realPropertyList = list(queryWrapper);
        List<RealPropertyVO> realPropertyVOS = realPropertyWrapper.entityToVO(realPropertyList);
        List<PageData> pageDataList = new ArrayList<>();
        try{
            if (CollectionUtil.isNotEmpty(realPropertyVOS)){
                for (RealPropertyVO vo : realPropertyVOS){
                    PageData pd = new PageData();
                    pd.put("id", vo.getId());
                    pd.put("UNITNAME", vo.getFillingUnitName());
                    pd.put("APPLICANTNAME", vo.getCreateUserName());
                    pd.put("applicantId", vo.getCreateUser());
                    pd.put("applyOrganizationId", vo.getFillingUnitId());
                    pd.put("formType", FormTypeConstant.PM_REAl_PROPERTY);
                    pd.put("orgName", vo.getFillingUnitName());
                    pageDataList.add(pd);
                }
            }

            return pageDataList;
        } catch (Exception e) {
            log.error(ExceptionUtils.getFullStackTrace(e));
        }
        return pageDataList;
    }

    @Override
    public List<Integer> getFormType() {
        return Arrays.asList(FormTypeConstant.PM_REAl_PROPERTY);
    }

    @Override
    public void goBackToStash(String formId) {
        Long id = Long.valueOf(formId);
        List<RealProperty> realPropertyList = list(new LambdaQueryWrapper<RealProperty>().eq(RealProperty::getInitialId, id));
        if (CollectionUtil.isNotEmpty(realPropertyList) && realPropertyList.size() > 1){
            throw new MyRuntimeException(new ObjResult("该不动产已进行其他操作，无法退回！"));
        }
        RealProperty realProperty = getById(id);
        if (realProperty.getStatus() == FormStatusConstant.FINISH){
            LambdaUpdateWrapper<RealProperty> updateWrapper = new LambdaUpdateWrapper<>();
            update(updateWrapper.eq(RealProperty::getId, id)
                    .set(RealProperty::getApprovedUser, null).set(RealProperty::getApprovedTime, null)
                    .set(RealProperty::getLandStatus, null).set(RealProperty::getEntrustUnitId, null).set(RealProperty::getIsEntrust, null));
        }

        handleStatus(Long.valueOf(formId), UNREVIEWED, null);
    }

    @Override
    public void exportTemplateExcel(HttpServletResponse response, OutputStream os) {
        try {
            String fname = "不动产登记导入模板";
            os = response.getOutputStream();//取得输出流
            response.reset();//清空输出流
            //下面是对中文文件名的处理
            response.setCharacterEncoding("UTF-8");//设置相应内容的编码格式
            InputStream inputStream = this.getClass().getResourceAsStream("/exceldemo/realPropertyImport.xlsx");
            fname = java.net.URLEncoder.encode(fname, "UTF-8");
            response.setHeader("Content-Disposition", "attachment;filename=" + new String(fname.getBytes("UTF-8"), "UTF-8") + ".xlsx");

            response.setContentType("application/msexcel");//定义输出类型
            int len;
            byte[] b = new byte[2048];
            while ((len = inputStream.read(b)) != -1) {
                os.write(b, 0, len);
            }
            response.setHeader("Content-Length", String.valueOf(inputStream.available()));

            inputStream.close();
            os.close();
        } catch (Exception e) {
            log.error(ExceptionUtils.getFullStackTrace(e));
        }
    }

    @Override
    @Async("ttlExecutor")
    public Future<ImportResult> importExcel(String progressId, InputStream inputStream) {
        String progress = "progress";
        String key = progressId + "#half:hour";
        try {
            byte[] bytes = IOUtils.toByteArray(inputStream);
            inputStream = new ByteArrayInputStream(bytes);

            Map<String, Map<String, String>> mapRef = getRef();
            List<Object> landList = new ArrayList<>();
            EasyExcel.read(inputStream).build()
                    .read(EasyExcel.readSheet(1).headRowNumber(1).head(LandInfoExcelBean.class)
                            .registerReadListener(new PageReadListener<>(list -> landList.addAll(list))).build());
            ImportExcelUtil.filterEmpty(landList);

            // 最新记录列表
            List<RealProperty> allList = realPropertyLatestService.findLatestList(null, null);
            //变更审批中列表
            List<RealProperty> changeAuditList = list(new LambdaQueryWrapper<RealProperty>()
                    .eq(RealProperty::getFormType, String.valueOf(FormTypeConstant.PM_REAl_PROPERTY_CHANGE)).ne(RealProperty::getStatus, FormStatusConstant.FINISH));
            //登记审批中列表
            List<RealProperty> auditList = list(new LambdaQueryWrapper<RealProperty>()
                    .eq(RealProperty::getFormType, String.valueOf(FormTypeConstant.PM_REAl_PROPERTY)).eq(RealProperty::getStatus, FormStatusConstant.FLOW));
            if (CollectionUtil.isNotEmpty(changeAuditList)){
                allList.addAll(changeAuditList);
            }
            if (CollectionUtil.isNotEmpty(auditList)){
                allList.addAll(auditList);
            }
            List<String> existLandNames = new ArrayList<>();
            if (CollectionUtil.isNotEmpty(allList)){
                existLandNames = allList.stream().filter(land -> land.getRealPropertyNature() == 1)
                        .map(RealProperty::getLandName).collect(Collectors.toList());
            }

            // 获取所有组织
            List<PageData> allOrg = orgzationDao.list(null);
            Map<String, PageData> orgNameMap = allOrg.stream().collect(Collectors.toMap(obj -> obj.getString("orgName"), a -> a, (a, b) -> b));

            ImportResult landResult = checkLandData(mapRef, landList, progressId, existLandNames,allOrg,orgNameMap);
            if (!landResult.isSuccess()) {
                CacheUtil.put(progress, progress, key, landResult.getMsg());
                return new AsyncResult<>(landResult);
            }

            inputStream.reset();
            List<Object> houseList = new ArrayList<>();
            EasyExcel.read(inputStream).build()
                    .read(EasyExcel.readSheet(2).headRowNumber(1).head(HouseInfoExcelBean.class)
                            .registerReadListener(new PageReadListener<>(list -> houseList.addAll(list))).build());
            ImportExcelUtil.filterEmpty(houseList);


            List<String> existHouseNames = new ArrayList<>();
            if (CollectionUtil.isNotEmpty(allList)){
                existHouseNames = allList.stream().filter(land -> land.getRealPropertyNature() == 2)
                        .map(RealProperty::getHouseName).collect(Collectors.toList());
            }

            ImportResult houseResult = checkHouseData(mapRef, houseList, progressId, existHouseNames,allOrg,orgNameMap);
            if (!houseResult.isSuccess()) {
                CacheUtil.put(progress, progress, key, houseResult.getMsg());
                return new AsyncResult<>(houseResult);
            }

            inputStream.reset();
            List<Object> estateList = new ArrayList<>();
            EasyExcel.read(inputStream).build()
                    .read(EasyExcel.readSheet(3).headRowNumber(1).head(EstateInfoExcelBean.class)
                            .registerReadListener(new PageReadListener<>(list -> estateList.addAll(list))).build());
            ImportExcelUtil.filterEmpty(estateList);


            List<String> existEstateNames = new ArrayList<>();
            if (CollectionUtil.isNotEmpty(allList)){
                existEstateNames = allList.stream().filter(a -> a.getRealPropertyNature() == 3)
                        .map(RealProperty::getHouseName).collect(Collectors.toList());
            }

            ImportResult estateResult = checkEstateData(mapRef, estateList, progressId, existEstateNames,allOrg,orgNameMap);
            if (!estateResult.isSuccess()) {
                CacheUtil.put(progress, progress, key, estateResult.getMsg());
                return new AsyncResult<>(estateResult);
            }

            String orgId = TokenUtil.getTokenOrgId();
            String groupId = orgzationService.getUnitId(orgId);

            int count = 0;
            int size = landList.size() + houseList.size() + estateList.size();
            // 土地登记
            for (Object object : landList) {
                RealProperty realProperty = (RealProperty) ImportExcelUtil.getEntityByExcelBean((LandInfoExcelBean)object, new RealProperty());
                //入库
                try {
                    RealProperty oldLand = findLandByName(realProperty.getLandName());

                    if (Optional.ofNullable(oldLand).isPresent()) {
                        realProperty.setId(oldLand.getId());
                        realProperty.setInitialId(oldLand.getId());
                    }
                    String orgName = ((LandInfoExcelBean) object).getOrgName();
                    PageData org = orgNameMap.get(orgName);
                    realProperty.setOrgId(org == null? groupId : org.getString("id"));
                    realProperty.setFillingUnitId(orgId);
                    realProperty.setRealPropertyNature(1);
                    saveOrUpdate(realProperty);
                    count++;
                    int value = count * 100 / size;
                    CacheUtil.put(progress, progress, key, value + 100);
                } catch (Exception e) {
                    log.error(ExceptionUtils.getFullStackTrace(e));
                    log.error(realProperty + "导入失败");
                    CacheUtil.put(progress, progress, key, realProperty + "导入失败");
                    return new AsyncResult<>(new ImportResult(false, realProperty + "导入失败"));
                }
            }

            // 房产登记
            for (Object object : houseList) {
                RealProperty realProperty = (RealProperty) ImportExcelUtil.getEntityByExcelBean((HouseInfoExcelBean)object, new RealProperty());
                //入库
                try {
                    RealProperty oldLand = findHouseByName(realProperty.getHouseName());

                    if (Optional.ofNullable(oldLand).isPresent()) {
                        realProperty.setId(oldLand.getId());
                        realProperty.setInitialId(oldLand.getId());
                    }
                    String orgName = ((HouseInfoExcelBean) object).getOrgName();
                    PageData org = orgNameMap.get(orgName);
                    realProperty.setOrgId(org == null? groupId : org.getString("id"));
                    realProperty.setFillingUnitId(orgId);
                    realProperty.setRealPropertyNature(2);
                    saveOrUpdate(realProperty);
                    count++;
                    int value = count * 100 / size;
                    CacheUtil.put(progress, progress, key, value + 100);
                } catch (Exception e) {
                    log.error(ExceptionUtils.getFullStackTrace(e));
                    log.error(realProperty + "导入失败");
                    CacheUtil.put(progress, progress, key, realProperty + "导入失败");
                    return new AsyncResult<>(new ImportResult(false, realProperty + "导入失败"));
                }
            }

            // 不动产登记
            for (Object object : estateList) {
                RealProperty realProperty = (RealProperty) ImportExcelUtil.getEntityByExcelBean((EstateInfoExcelBean)object, new RealProperty());
                //入库
                try {
                    RealProperty oldLand = findHouseByName(realProperty.getHouseName());

                    if (Optional.ofNullable(oldLand).isPresent()) {
                        realProperty.setId(oldLand.getId());
                        realProperty.setInitialId(oldLand.getId());
                    }
                    String orgName = ((EstateInfoExcelBean) object).getOrgName();
                    PageData org = orgNameMap.get(orgName);
                    realProperty.setOrgId(org == null? groupId : org.getString("id"));
                    realProperty.setFillingUnitId(orgId);
                    realProperty.setRealPropertyNature(3);
                    saveOrUpdate(realProperty);
                    count++;
                    int value = count * 100 / size;
                    CacheUtil.put(progress, progress, key, value + 100);
                } catch (Exception e) {
                    log.error(ExceptionUtils.getFullStackTrace(e));
                    log.error(realProperty + "导入失败");
                    CacheUtil.put(progress, progress, key, realProperty + "导入失败");
                    return new AsyncResult<>(new ImportResult(false, realProperty + "导入失败"));
                }
            }

        } catch (Exception e) {
            log.error(ExceptionUtils.getFullStackTrace(e));
            log.error("解析失败");
            CacheUtil.put(progress, progress, key, "解析失败");
            return new AsyncResult<>(new ImportResult(false, "解析失败"));
        }

        CacheUtil.put(progress, progress, key, "导入成功");
        return new AsyncResult<>(new ImportResult(true, "导入成功"));
    }

    @Override
    public String checkName(RealProperty realProperty) {

        if (realProperty.getRealPropertyNature() == null){
            return "不动产性质为空";
        }

        int realPropertyNature = realProperty.getRealPropertyNature();
        if (realPropertyNature != 1 && realPropertyNature != 2 && realPropertyNature != 3){
            return "不动产性质不是1、2或3";
        }

        RealProperty old;
        String message = null;
        List<RealProperty> latestList = realPropertyLatestService.findLatestList(null, null);
        List<String> landNameList = Optional.ofNullable(latestList).orElse(new ArrayList<>())
                .stream().filter(p -> (!p.getInitialId().equals(realProperty.getInitialId()))
                        && p.getRealPropertyNature() == 1 && StringUtil.isNotBlank(p.getLandName()))
                .map(RealProperty::getLandName).collect(Collectors.toList());
        List<String> houseNameList = Optional.ofNullable(latestList).orElse(new ArrayList<>())
                .stream().filter(p -> (!p.getInitialId().equals(realProperty.getInitialId()))
                        && p.getRealPropertyNature() == 2 && StringUtil.isNotBlank(p.getHouseName()))
                .map(RealProperty::getHouseName).collect(Collectors.toList());

        if (realPropertyNature == 1){
            String landName = realProperty.getLandName();
            if (StringUtil.isBlank(landName)){
                return "土地名称为空";
            }

            if (landNameList.contains(landName)){
                return "土地名称重复";
            }

            old = getOne(new LambdaQueryWrapper<RealProperty>()
                    .eq(RealProperty::getRealPropertyNature, 1)
                    .ne(RealProperty::getStatus, FormStatusConstant.FINISH)
                    .eq(RealProperty::getLandName, realProperty.getLandName()));
            if (old == null || old.getId().equals(realProperty.getId())){
                return null;
            }
            return "土地名称重复";
        }

        if (realPropertyNature == 2){
            String houseName = realProperty.getHouseName();
            if (StringUtil.isBlank(houseName)){
                return "房产名称为空";
            }

            if (houseNameList.contains(houseName)){
                return "房产名称重复";
            }

            old = getOne(new LambdaQueryWrapper<RealProperty>()
                    .eq(RealProperty::getRealPropertyNature, 2)
                    .ne(RealProperty::getStatus, FormStatusConstant.FINISH)
                    .eq(RealProperty::getHouseName, houseName));
            if (old == null || old.getId().equals(realProperty.getId())){
                return null;
            }
            return "房产名称重复";
        }

        return message;
    }

    @Override
    public String checkEntrust(RealProperty realProperty) {
        if (realProperty.getId() == null){
            return "单据id为null";
        }

        if (StringUtil.isBlank(realProperty.getEntrustUnitId())){
            return "委托单位id为null";
        }
        RealProperty old = getById(realProperty.getId());
        if (old == null){
            return "该单据不存在";
        }

        if (old.getIsEntrust() != null && old.getIsEntrust() == 2){
            return "已存在委托单位！";
        }
        return null;
    }

    @Override
    public boolean entrust(RealProperty realProperty) {
        if (realProperty.getId() == null){
            return true;
        }
        LambdaUpdateWrapper<RealProperty> updateWrapper = new LambdaUpdateWrapper();
        updateWrapper.eq(RealProperty::getId, realProperty.getId())
                .set(RealProperty::getEntrustUnitId, realProperty.getEntrustUnitId()).set(RealProperty::getIsEntrust, "2");
        return update(updateWrapper);
    }

    @Override
    public String checkCancelEntrust(RealProperty realProperty) {
        if (realProperty.getId() == null){
            return "单据id为null";
        }

        RealProperty old = getById(realProperty.getId());
        if (old == null){
            return "该单据不存在";
        }

        if (old.getIsEntrust() != null && old.getIsEntrust() != 2){
            return "该单据未委托！";
        }
        return null;
    }

    @Override
    public boolean cancelEntrust(RealProperty realProperty) {
        if (realProperty.getId() == null){
            return true;
        }
        LambdaUpdateWrapper<RealProperty> updateWrapper = new LambdaUpdateWrapper();
        updateWrapper.eq(RealProperty::getId, realProperty.getId())
                .set(RealProperty::getEntrustUnitId, "").set(RealProperty::getIsEntrust, "1");
        return update(updateWrapper);
    }

    @Override
    public RealProperty findLatestByInitialId(Long initialId) {
        return getOne(new LambdaQueryWrapper<RealProperty>().eq(RealProperty::getInitialId, initialId)
                .eq(RealProperty::getIsLatest, 2));
    }

    @Override
    public List<RealPropertyYearInfoVO> toQuoList(List<RealProperty> realPropertyList, String year) {
        if (CollectionUtil.isEmpty(realPropertyList)){
            return new ArrayList<>();
        }

        List<RealPropertyVO> realPropertyVOS = realPropertyWrapper.entityToVO(realPropertyList);
        List<RealPropertyQuo> realPropertyQuoList = realPropertyQuoService.list(new LambdaQueryWrapper<RealPropertyQuo>().eq(RealPropertyQuo::getYear, year)
                .eq(RealPropertyQuo::getCreateCompanyId, TokenUtil.getTokenOrgId()));
        Map<Long, RealPropertyQuo> map = realPropertyQuoList.stream()
                .filter(quo -> quo.getRealPropertyId() != null).collect(Collectors.toMap(RealPropertyQuo::getRealPropertyId, quo -> quo));

        List<RealPropertyYearInfoVO> realPropertyYearInfoVOS = new ArrayList<>();

        for (RealPropertyVO realPropertyVO : realPropertyVOS){
            RealPropertyYearInfoVO yearInfoVO = realPropertyWrapper.realPropertyVOToRealPropertyYearInfoVO(realPropertyVO);
            yearInfoVO.setRealPropertyName(realPropertyVO.getLandName());
            if (realPropertyVO.getRealPropertyNature() != null && realPropertyVO.getRealPropertyNature() == 2){
                yearInfoVO.setRealPropertyName(realPropertyVO.getHouseName());
            }

            if (map.containsKey(realPropertyVO.getInitialId())){
                RealPropertyQuo quo = map.get(realPropertyVO.getInitialId());
                yearInfoVO.setId(quo.getId());
                yearInfoVO.setStatus(quo.getStatus());
            }else {
                yearInfoVO.setId(null);
                yearInfoVO.setStatus(FormStatusConstant.NOFILLING);
            }
            yearInfoVO.setYear(year);
            realPropertyYearInfoVOS.add(yearInfoVO);
        }


        return realPropertyYearInfoVOS;
    }


    @Override
    public IPage<RealPropertyFormVO> formPage(IPage<RealPropertyFormVO> page, PageData pd) throws Exception{
        List<RealPropertyFormVO> resultList=realPropertyMapper.realPropertyFormList(page,pd);
        List<PageData> orgList=orgzationDao.getGroupOrgList();
        Map<String,String> orgMap=orgList.stream().collect(Collectors.toMap(record->record.getString("orgCode"),record->record.getString("name"),(newValue,oldValue)->newValue));
        for(RealPropertyFormVO realPropertyFormVO:resultList){
            String orgCode=realPropertyFormVO.getOrgCode();
            //广电合并和城投合并节点单独处理
            if(orgCode.length()>8&&(orgCode.indexOf("00010106")!=-1||orgCode.indexOf("00010109")!=-1)){
                orgCode=orgCode.substring(0,10);
                String orgName=orgMap.get(orgCode);
                if(StringUtil.isNotBlank(orgName)) realPropertyFormVO.setFillingUnitName(orgName);
            }else if(orgCode.length()>=8){
                orgCode=orgCode.substring(0,8);
                String orgName=orgMap.get(orgCode);
                if(StringUtil.isNotBlank(orgName)) realPropertyFormVO.setFillingUnitName(orgName);
            }
        }
        return page.setRecords(resultList);
    }

    @Override
    public void exportRepropertyExcel(IPage<RealPropertyFormVO> page,PageData pd,HttpServletResponse response) throws Exception{
        IPage<RealPropertyFormVO> result=page.setRecords(realPropertyMapper.realPropertyFormList(page,pd));
        List<RealPropertyFormVO> list=result.getRecords();

//        ListResult<PageData> orgs = orgzationService.getSubordinatePassFictitious();
//        if (CollectionUtil.isNotEmpty(list) && CollectionUtil.isNotEmpty(list)) {
//            String topName = orgs.getList().get(0).getString("orgName");
//            list.forEach(p -> p.setFillingUnitName(topName));
//        }

        valueSet(list);
//        list = list.stream().filter(p -> StringUtil.isNotBlank(p.getString("orgCode"))).collect(Collectors.toList());
        String separator = File.separator;
        String excelName="";
        Integer type=pd.getInteger("type");
        if(type.intValue()==1){
            excelName="realpropertyLand.xlsx";
        }else if(type.intValue()==2){
            excelName="realpropertyHouse.xlsx";
        }else if(type.intValue()==3){
            excelName="realpropertyEstate.xlsx";
        }
        String exlPath = separator + "exceldemo" + separator + excelName;
        InputStream inputStream = getClass().getClassLoader().getResourceAsStream(exlPath);
        String fileName = URLEncoder.encode("不动产登记信息", "UTF-8");
        response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
        // 设置响应头和客户端保存文件名
        response.setCharacterEncoding("utf-8");
        OutputStream outputStream = response.getOutputStream();// 取得输出流
        ExcelWriter excelWriter = EasyExcel.write(outputStream).withTemplate(inputStream).build();
        WriteSheet writeSheet = EasyExcel.writerSheet().build();
        FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
        excelWriter.fill(list, fillConfig, writeSheet);
        excelWriter.finish();
        inputStream.close();
        outputStream.close();
    }

    @Override
    public List<RealPropertyFormVO> formList(PageData pd) throws Exception {
        List<RealPropertyFormVO> resultList=new ArrayList<>();
        List<RealPropertyFormVO> list=realPropertyMapper.realPropertyGroupFormList(pd);
        List<PageData> orgList=orgzationDao.getGroupOrgList();
        Map<String,String> orgMap=orgList.stream().collect(Collectors.toMap(record->record.getString("orgCode"),record->record.getString("name")));
        for(RealPropertyFormVO realPropertyFormVO:list){
            String orgCode=realPropertyFormVO.getOrgCode();
            //广电合并和城投合并节点单独处理
            if(orgCode.length()>8&&(orgCode.indexOf("00010106")!=-1||orgCode.indexOf("00010109")!=-1||orgCode.indexOf("0001012301")!=-1||orgCode.indexOf("0001012302")!=-1)){
                orgCode=orgCode.substring(0,10);
                String orgName=orgMap.get(orgCode);
                realPropertyFormVO.setFillingUnitName(orgName);
            }else if(orgCode.length()>=8){
                orgCode=orgCode.substring(0,8);
                String orgName=orgMap.get(orgCode);
                realPropertyFormVO.setFillingUnitName(orgName);
            }
        }
        List<RealPropertyFormVO> landList=list.stream().filter(record->record.getRealPropertyNature()==1).collect(Collectors.toList());
        List<RealPropertyFormVO> houseList=list.stream().filter(record->record.getRealPropertyNature()==2).collect(Collectors.toList());
        Map<String,List<RealPropertyFormVO>> landMap=landList.stream().collect(Collectors.groupingBy(record->record.getFillingUnitName()));

        BigDecimal landTotalAreaAll=new BigDecimal(0);
        BigDecimal landMadeAreaAll=new BigDecimal(0);
        BigDecimal landNoMadeAreaAll=new BigDecimal(0);
        BigDecimal landRentableAreaAll=new BigDecimal(0);
        BigDecimal landUnusedAreaAll=new BigDecimal(0);
        BigDecimal landLeasedAreaAll=new BigDecimal(0);
        BigDecimal landReceivableRentAll=new BigDecimal(0);
        BigDecimal landPaidRentAll=new BigDecimal(0);
        int landPaidParkingNumberAll=0;
        BigDecimal landReceivableAmountAll=new BigDecimal(0);
        BigDecimal landPaidAmountAll=new BigDecimal(0);
        int landNumAll=0;
        for(String key:landMap.keySet()){
            RealPropertyFormVO real=new RealPropertyFormVO();
            List<RealPropertyFormVO> rList=landMap.get(key);
            BigDecimal landTotalArea=rList.stream().map(record->record.getLandTotalArea()==null?new BigDecimal(0):record.getLandTotalArea()).reduce(BigDecimal.ZERO,BigDecimal::add);
            BigDecimal landMadeArea=rList.stream().map(record->record.getLandMadeArea()==null?new BigDecimal(0):record.getLandMadeArea()).reduce(BigDecimal.ZERO,BigDecimal::add);
            BigDecimal landNoMadeArea=rList.stream().map(record->record.getLandNoMadeArea()==null?new BigDecimal(0):record.getLandNoMadeArea()).reduce(BigDecimal.ZERO,BigDecimal::add);
            BigDecimal rentableArea=rList.stream().map(record->record.getRentableArea()==null?new BigDecimal(0):record.getRentableArea()).reduce(BigDecimal.ZERO,BigDecimal::add);
            BigDecimal leasedArea=rList.stream().map(record->record.getLeasedArea()==null?new BigDecimal(0):record.getLeasedArea()).reduce(BigDecimal.ZERO,BigDecimal::add);
            BigDecimal unusedArea=rentableArea.subtract(leasedArea);
            BigDecimal receivableRent=rList.stream().map(record->record.getReceivableRent()==null?new BigDecimal(0):record.getReceivableRent()).reduce(BigDecimal.ZERO,BigDecimal::add);
            BigDecimal paidRent=rList.stream().map(record->record.getPaidRent()==null?new BigDecimal(0):record.getPaidRent()).reduce(BigDecimal.ZERO,BigDecimal::add);
            int paidParkingNumber=rList.stream().mapToInt(record->record.getPaidParkingNumber()==null?0:record.getPaidParkingNumber()).sum();
            BigDecimal receivableAmount=rList.stream().map(record->record.getReceivableAmount()==null?new BigDecimal(0):record.getReceivableAmount()).reduce(BigDecimal.ZERO,BigDecimal::add);
            BigDecimal paidAmount=rList.stream().map(record->record.getPaidAmount()==null?new BigDecimal(0):record.getPaidAmount()).reduce(BigDecimal.ZERO,BigDecimal::add);
            real.setTotalArea(landTotalArea);
            real.setMadeArea(landMadeArea);
            real.setNoMadeArea(landNoMadeArea);
            real.setRentableArea(rentableArea);
            real.setLeasedArea(leasedArea);
            real.setUnusedArea(unusedArea);
            real.setReceivableRent(receivableRent);
            real.setPaidRent(paidRent);
            real.setPaidParkingNumber(paidParkingNumber);
            real.setReceivableAmount(receivableAmount);
            real.setPaidAmount(paidAmount);
            real.setNum(rList.size());
            real.setRealPropertyNatureName("土地");
            real.setFillingUnitName(key);
            resultList.add(real);
            landTotalAreaAll=landTotalAreaAll.add(landTotalArea);
            landMadeAreaAll=landMadeAreaAll.add(landMadeArea);
            landNoMadeAreaAll=landNoMadeAreaAll.add(landNoMadeArea);
            landRentableAreaAll=landRentableAreaAll.add(rentableArea);
            landUnusedAreaAll=landUnusedAreaAll.add(unusedArea);
            landLeasedAreaAll=landLeasedAreaAll.add(leasedArea);
            landReceivableRentAll=landReceivableRentAll.add(receivableRent);
            landPaidRentAll=landPaidRentAll.add(paidRent);
            landPaidParkingNumberAll=landPaidParkingNumberAll+paidParkingNumber;
            landReceivableAmountAll=landReceivableAmountAll.add(receivableAmount);
            landPaidAmountAll=landPaidAmountAll.add(paidAmount);
            landNumAll=landNumAll+rList.size();
        }
        RealPropertyFormVO landRealAll=new RealPropertyFormVO();
        landRealAll.setTotalArea(landTotalAreaAll);
        landRealAll.setMadeArea(landMadeAreaAll);
        landRealAll.setNoMadeArea(landNoMadeAreaAll);
        landRealAll.setRentableArea(landRentableAreaAll);
        landRealAll.setLeasedArea(landLeasedAreaAll);
        landRealAll.setUnusedArea(landUnusedAreaAll);
        landRealAll.setReceivableRent(landReceivableRentAll);
        landRealAll.setPaidRent(landPaidRentAll);
        landRealAll.setPaidParkingNumber(landPaidParkingNumberAll);
        landRealAll.setReceivableAmount(landReceivableAmountAll);
        landRealAll.setPaidAmount(landPaidAmountAll);
        landRealAll.setNum(landNumAll);
        landRealAll.setRealPropertyNatureName("土地合计");
        resultList.add(landRealAll);

        Map<String,List<RealPropertyFormVO>> houseMap=houseList.stream().collect(Collectors.groupingBy(record->record.getFillingUnitName()));

        BigDecimal houseTotalAreaAll=new BigDecimal(0);
        BigDecimal houseMadeAreaAll=new BigDecimal(0);
        BigDecimal houseNoMadeAreaAll=new BigDecimal(0);
        BigDecimal houseRentableAreaAll=new BigDecimal(0);
        BigDecimal houseUnusedAreaAll=new BigDecimal(0);
        BigDecimal houseLeasedAreaAll=new BigDecimal(0);
        BigDecimal houseReceivableRentAll=new BigDecimal(0);
        BigDecimal housePaidRentAll=new BigDecimal(0);
        int housePaidParkingNumberAll=0;
        BigDecimal houseReceivableAmountAll=new BigDecimal(0);
        BigDecimal housePaidAmountAll=new BigDecimal(0);
        int houseNumAll=0;
        for(String key:houseMap.keySet()){
            RealPropertyFormVO real=new RealPropertyFormVO();
            List<RealPropertyFormVO> rList=houseMap.get(key);
            BigDecimal houseTotalArea=rList.stream().map(record->record.getHouseTotalArea()==null?new BigDecimal(0):record.getHouseTotalArea()).reduce(BigDecimal.ZERO,BigDecimal::add);
            BigDecimal houseMadeArea=rList.stream().map(record->record.getHouseMadeArea()==null?new BigDecimal(0):record.getHouseMadeArea()).reduce(BigDecimal.ZERO,BigDecimal::add);
            BigDecimal houseNoMadeArea=rList.stream().map(record->record.getHouseNoMadeArea()==null?new BigDecimal(0):record.getHouseNoMadeArea()).reduce(BigDecimal.ZERO,BigDecimal::add);
            BigDecimal rentableArea=rList.stream().map(record->record.getRentableArea()==null?new BigDecimal(0):record.getRentableArea()).reduce(BigDecimal.ZERO,BigDecimal::add);
            BigDecimal leasedArea=rList.stream().map(record->record.getLeasedArea()==null?new BigDecimal(0):record.getLeasedArea()).reduce(BigDecimal.ZERO,BigDecimal::add);
            BigDecimal unusedArea=rentableArea.subtract(leasedArea);
            BigDecimal receivableRent=rList.stream().map(record->record.getReceivableRent()==null?new BigDecimal(0):record.getReceivableRent()).reduce(BigDecimal.ZERO,BigDecimal::add);
            BigDecimal paidRent=rList.stream().map(record->record.getPaidRent()==null?new BigDecimal(0):record.getPaidRent()).reduce(BigDecimal.ZERO,BigDecimal::add);
            int paidParkingNumber=rList.stream().mapToInt(record->record.getPaidParkingNumber()==null?0:record.getPaidParkingNumber()).sum();
            BigDecimal receivableAmount=rList.stream().map(record->record.getReceivableAmount()==null?new BigDecimal(0):record.getReceivableAmount()).reduce(BigDecimal.ZERO,BigDecimal::add);
            BigDecimal paidAmount=rList.stream().map(record->record.getPaidAmount()==null?new BigDecimal(0):record.getPaidAmount()).reduce(BigDecimal.ZERO,BigDecimal::add);
            real.setTotalArea(houseTotalArea);
            real.setMadeArea(houseMadeArea);
            real.setNoMadeArea(houseNoMadeArea);
            real.setRentableArea(rentableArea);
            real.setLeasedArea(leasedArea);
            real.setUnusedArea(unusedArea);
            real.setReceivableRent(receivableRent);
            real.setPaidRent(paidRent);
            real.setPaidParkingNumber(paidParkingNumber);
            real.setReceivableAmount(receivableAmount);
            real.setPaidAmount(paidAmount);
            real.setNum(rList.size());
            real.setRealPropertyNatureName("房产");
            real.setFillingUnitName(key);
            resultList.add(real);
            houseTotalAreaAll=houseTotalAreaAll.add(houseTotalArea);
            houseMadeAreaAll=houseMadeAreaAll.add(houseMadeArea);
            houseNoMadeAreaAll=houseNoMadeAreaAll.add(houseNoMadeArea);
            houseRentableAreaAll=houseRentableAreaAll.add(rentableArea);
            houseUnusedAreaAll=houseUnusedAreaAll.add(unusedArea);
            houseLeasedAreaAll=houseLeasedAreaAll.add(leasedArea);
            houseReceivableRentAll=houseReceivableRentAll.add(receivableRent);
            housePaidRentAll=housePaidRentAll.add(paidRent);
            housePaidParkingNumberAll=housePaidParkingNumberAll+paidParkingNumber;
            houseReceivableAmountAll=houseReceivableAmountAll.add(receivableAmount);
            housePaidAmountAll=housePaidAmountAll.add(paidAmount);
            houseNumAll=houseNumAll+rList.size();
        }
        RealPropertyFormVO houseRealAll=new RealPropertyFormVO();
        houseRealAll.setTotalArea(houseTotalAreaAll);
        houseRealAll.setMadeArea(houseMadeAreaAll);
        houseRealAll.setNoMadeArea(houseNoMadeAreaAll);
        houseRealAll.setRentableArea(houseRentableAreaAll);
        houseRealAll.setLeasedArea(houseLeasedAreaAll);
        houseRealAll.setUnusedArea(houseUnusedAreaAll);
        houseRealAll.setReceivableRent(houseReceivableRentAll);
        houseRealAll.setPaidRent(housePaidRentAll);
        houseRealAll.setPaidParkingNumber(housePaidParkingNumberAll);
        houseRealAll.setReceivableAmount(houseReceivableAmountAll);
        houseRealAll.setPaidAmount(housePaidAmountAll);
        houseRealAll.setNum(houseNumAll);
        houseRealAll.setRealPropertyNatureName("房产合计");
        resultList.add(houseRealAll);

        RealPropertyFormVO realAll=new RealPropertyFormVO();
        realAll.setTotalArea(houseTotalAreaAll.add(landTotalAreaAll));
        realAll.setMadeArea(houseMadeAreaAll.add(landMadeAreaAll));
        realAll.setNoMadeArea(houseNoMadeAreaAll.add(landNoMadeAreaAll));
        realAll.setRentableArea(houseRentableAreaAll.add(landRentableAreaAll));
        realAll.setLeasedArea(houseLeasedAreaAll.add(landLeasedAreaAll));
        realAll.setUnusedArea(houseUnusedAreaAll.add(landUnusedAreaAll));
        realAll.setReceivableRent(houseReceivableRentAll.add(landReceivableRentAll));
        realAll.setPaidRent(housePaidRentAll.add(landPaidRentAll));
        realAll.setPaidParkingNumber(housePaidParkingNumberAll+landPaidParkingNumberAll);
        realAll.setReceivableAmount(houseReceivableAmountAll.add(landReceivableAmountAll));
        realAll.setPaidAmount(housePaidAmountAll.add(landPaidAmountAll));
        realAll.setNum(houseNumAll+landNumAll);
        realAll.setRealPropertyNatureName("不动产总计（土地和房产合计）");
        resultList.add(realAll);
        return resultList;
    }

    @Override
    public List<RealPropertyFormVO> houseBusinessFormList(PageData pd) throws Exception{
        List<RealPropertyFormVO> resultList=new ArrayList<>();
        List<RealPropertyFormVO> list=realPropertyMapper.realPropertyGroupFormList(pd);
        List<PageData> orgList=orgzationDao.getGroupOrgList();
        Map<String,String> orgMap=orgList.stream().collect(Collectors.toMap(record->record.getString("orgCode"),record->record.getString("name")));
        for(RealPropertyFormVO realPropertyFormVO:list){
            String orgCode=realPropertyFormVO.getOrgCode();
            //广电合并和城投合并节点单独处理
            if(orgCode.length()>8&&(orgCode.indexOf("00010106")!=-1||orgCode.indexOf("00010109")!=-1||orgCode.indexOf("0001012301")!=-1||orgCode.indexOf("0001012302")!=-1)){
                orgCode=orgCode.substring(0,10);
                String orgName=orgMap.get(orgCode);
                realPropertyFormVO.setFillingUnitName(orgName);
            }else if(orgCode.length()>=8){
                orgCode=orgCode.substring(0,8);
                String orgName=orgMap.get(orgCode);
                realPropertyFormVO.setFillingUnitName(orgName);
            }
            realPropertyFormVO.setTotalArea(realPropertyFormVO.getHouseTotalArea()==null?new BigDecimal(0):realPropertyFormVO.getHouseTotalArea());
            realPropertyFormVO.setMadeArea(realPropertyFormVO.getHouseMadeArea()==null?new BigDecimal(0):realPropertyFormVO.getHouseMadeArea());
            realPropertyFormVO.setNoMadeArea(realPropertyFormVO.getHouseNoMadeArea()==null?new BigDecimal(0):realPropertyFormVO.getHouseNoMadeArea());
            BigDecimal rentableArea=realPropertyFormVO.getRentableArea()==null?new BigDecimal(0):realPropertyFormVO.getRentableArea();
            BigDecimal leasedArea=realPropertyFormVO.getLeasedArea()==null?new BigDecimal(0):realPropertyFormVO.getLeasedArea();
            realPropertyFormVO.setRentableArea(rentableArea);
            realPropertyFormVO.setLeasedArea(leasedArea);
            realPropertyFormVO.setUnusedArea(rentableArea.subtract(leasedArea));
            realPropertyFormVO.setUnusedArea(realPropertyFormVO.getUnusedArea()==null?new BigDecimal(0):realPropertyFormVO.getUnusedArea());
            realPropertyFormVO.setReceivableRent(realPropertyFormVO.getReceivableRent()==null?new BigDecimal(0):realPropertyFormVO.getHouseNoMadeArea());
            realPropertyFormVO.setPaidRent(realPropertyFormVO.getPaidRent()==null?new BigDecimal(0):realPropertyFormVO.getHouseNoMadeArea());
            realPropertyFormVO.setPaidParkingNumber(realPropertyFormVO.getParkingNumber()==null?0:realPropertyFormVO.getParkingNumber());
            realPropertyFormVO.setReceivableAmount(realPropertyFormVO.getReceivableAmount()==null?new BigDecimal(0):realPropertyFormVO.getHouseNoMadeArea());
            realPropertyFormVO.setPaidAmount(realPropertyFormVO.getPaidAmount()==null?new BigDecimal(0):realPropertyFormVO.getHouseNoMadeArea());
        }
        resultList=list.stream().sorted(Comparator.comparing(RealPropertyFormVO::getFillingUnitName)).collect(Collectors.toList());
        BigDecimal houseTotalAreaAll=list.stream().map(record->record.getHouseTotalArea()==null?new BigDecimal(0):record.getHouseTotalArea()).reduce(BigDecimal.ZERO,BigDecimal::add);
        BigDecimal houseMadeAreaAll=list.stream().map(record->record.getHouseMadeArea()==null?new BigDecimal(0):record.getHouseMadeArea()).reduce(BigDecimal.ZERO,BigDecimal::add);
        BigDecimal houseNoMadeAreaAll=list.stream().map(record->record.getHouseNoMadeArea()==null?new BigDecimal(0):record.getHouseNoMadeArea()).reduce(BigDecimal.ZERO,BigDecimal::add);
        BigDecimal houseRentableAreaAll=list.stream().map(record->record.getRentableArea()==null?new BigDecimal(0):record.getRentableArea()).reduce(BigDecimal.ZERO,BigDecimal::add);
        BigDecimal houseLeasedAreaAll=list.stream().map(record->record.getLeasedArea()==null?new BigDecimal(0):record.getLeasedArea()).reduce(BigDecimal.ZERO,BigDecimal::add);
        BigDecimal houseUnusedAreaAll=houseRentableAreaAll.subtract(houseLeasedAreaAll);
        BigDecimal houseReceivableRentAll=list.stream().map(record->record.getReceivableRent()==null?new BigDecimal(0):record.getReceivableRent()).reduce(BigDecimal.ZERO,BigDecimal::add);
        BigDecimal housePaidRentAll=list.stream().map(record->record.getPaidRent()==null?new BigDecimal(0):record.getPaidRent()).reduce(BigDecimal.ZERO,BigDecimal::add);
        int housePaidParkingNumberAll=list.stream().mapToInt(record->record.getPaidParkingNumber()==null?0:record.getPaidParkingNumber()).sum();
        BigDecimal houseReceivableAmountAll=list.stream().map(record->record.getReceivableAmount()==null?new BigDecimal(0):record.getReceivableAmount()).reduce(BigDecimal.ZERO,BigDecimal::add);
        BigDecimal housePaidAmountAll=list.stream().map(record->record.getPaidAmount()==null?new BigDecimal(0):record.getPaidAmount()).reduce(BigDecimal.ZERO,BigDecimal::add);
        RealPropertyFormVO houseRealAll=new RealPropertyFormVO();
        houseRealAll.setTotalArea(houseTotalAreaAll);
        houseRealAll.setMadeArea(houseMadeAreaAll);
        houseRealAll.setNoMadeArea(houseNoMadeAreaAll);
        houseRealAll.setRentableArea(houseRentableAreaAll);
        houseRealAll.setLeasedArea(houseLeasedAreaAll);
        houseRealAll.setUnusedArea(houseUnusedAreaAll);
        houseRealAll.setReceivableRent(houseReceivableRentAll);
        houseRealAll.setPaidRent(housePaidRentAll);
        houseRealAll.setPaidParkingNumber(housePaidParkingNumberAll);
        houseRealAll.setReceivableAmount(houseReceivableAmountAll);
        houseRealAll.setPaidAmount(housePaidAmountAll);
        houseRealAll.setNum(list.size());
        houseRealAll.setHouseName("登记数量："+list.size());
        houseRealAll.setFillingUnitName("合计");
        resultList.add(houseRealAll);
        return resultList;
    }

    @Override
    public String ythSubmitBatch(String data) {
        YthResult ythResult = new YthResult();
        //成功的id集合
        List<String> successIds = new ArrayList<>();
        //失败的id集合
        List<String> failIds = new ArrayList<>();
        //失败的原因
        List<String> failReasons = new ArrayList<>();
        //将json字符串转换成list
        List<RealProperty> dataList = JSON.parseArray(data, RealProperty.class);
        if (CollectionUtil.isEmpty(dataList)){
            failReasons.add("数据为空");
            ythResult.setFailReason(StringUtils.join(failReasons, StringPool.COMMA));
            return JSON.toJSONString(ythResult);
        }

        List<RealProperty> latestList = realPropertyLatestService.findLatestList(null, null);
        List<RealProperty> flowList = list(new LambdaQueryWrapper<RealProperty>()
                .and(wrapper -> wrapper.eq(RealProperty::getStatus, FormStatusConstant.FLOW)
                        .eq(RealProperty::getFormType, FormTypeConstant.PM_REAl_PROPERTY)
                        .or().ne(RealProperty::getStatus, FormStatusConstant.FINISH)
                        .eq(RealProperty::getFormType, FormTypeConstant.PM_REAl_PROPERTY_CHANGE)));
        if (CollectionUtil.isNotEmpty(latestList)){
            latestList.addAll(flowList);
        }
        List<String> cantSubmitList = latestList.stream().map(realProperty -> realProperty.getRealPropertyNature() + StringPool.DASH +
                (realProperty.getRealPropertyNature() == 1 ? realProperty.getLandName() : realProperty.getHouseName())).collect(Collectors.toList());

        List<RealProperty> oldList = list(new LambdaQueryWrapper<RealProperty>()
                .eq(RealProperty::getFormType, FormTypeConstant.PM_REAl_PROPERTY)
                .in(RealProperty::getStatus, Stream.of(FormStatusConstant.STASH,
                        UNREVIEWED, FormStatusConstant.REJECT).collect(Collectors.toList())));
        Map<String, RealProperty> oldMap = oldList.stream().collect(Collectors.toMap(realProperty -> realProperty.getRealPropertyNature() + StringPool.DASH +
                (realProperty.getRealPropertyNature() == 1 ? realProperty.getLandName() : realProperty.getHouseName()), Function.identity()));

        List<Org> orgList = orgService.getYthOrgList();
        Map<String, Org> dataSourceIdOrgMap = orgList.stream().collect(Collectors.toMap(Org::getDataSourceId, Function.identity()));
        List<RealProperty> submitList = new ArrayList<>();
        Date now = DateUtil.now();
        for (RealProperty realProperty : dataList){
            if (realProperty.getRealPropertyNature() == null ||
                    (realProperty.getRealPropertyNature() != 1 && realProperty.getRealPropertyNature() != 2)){
                failIds.add(realProperty.getDataSourceId());
                failReasons.add(realProperty.getDataSourceId() + "realPropertyNature 错误");
                continue;
            }
            String key = realProperty.getRealPropertyNature() + StringPool.DASH +
                    (realProperty.getRealPropertyNature() == 1 ? realProperty.getLandName() : realProperty.getHouseName());
            if (cantSubmitList.contains(key)){
                failIds.add(realProperty.getDataSourceId());
                failReasons.add("该不动产已登记或在流程中");
                continue;
            }
            if (successIds.contains(realProperty.getDataSourceId())){
                failIds.add(realProperty.getDataSourceId());
                failReasons.add(realProperty.getDataSourceId() + "id重复");
                continue;
            }

            successIds.add(realProperty.getDataSourceId());
            if (oldMap.containsKey(key)){
                realProperty.setId(oldMap.get(key).getId());
                realProperty.setCode(oldMap.get(key).getCode());
                realProperty.setUpdateTime(now);
            }else {
                realProperty.setCode(formCodeService.getCode(FormTypeConstant.PM_REAl_PROPERTY));
                realProperty.setCreateTime(now);
            }
            if (StringUtil.isNotBlank(realProperty.getOrgId()) && dataSourceIdOrgMap.containsKey(realProperty.getOrgId())){
                realProperty.setOrgId(dataSourceIdOrgMap.get(realProperty.getOrgId()).getId());
            }
            if (StringUtil.isNotBlank(realProperty.getEntrustUnitId()) && dataSourceIdOrgMap.containsKey(realProperty.getEntrustUnitId())){
                realProperty.setEntrustUnitId(dataSourceIdOrgMap.get(realProperty.getEntrustUnitId()).getId());
            }
            if (StringUtil.isNotBlank(realProperty.getFillingUnitId()) && dataSourceIdOrgMap.containsKey(realProperty.getFillingUnitId())){
                realProperty.setFillingUnitId(dataSourceIdOrgMap.get(realProperty.getFillingUnitId()).getId());
                realProperty.setCreateCompanyId(realProperty.getFillingUnitId());
            }
            realProperty.setFormType(String.valueOf(FormTypeConstant.PM_REAl_PROPERTY));
            realProperty.setVersion(1);
            realProperty.setDataSource(YthConstant.DATA_NINGBO);
            realProperty.setIsDeleted(0);
            submitList.add(realProperty);
        }

        if (CollectionUtil.isNotEmpty(submitList)){
            saveOrUpdateBatch(submitList);
        }

        ythResult.setSuccessIds(successIds);
        ythResult.setFailIds(failIds);
        ythResult.setFailReason(StringUtils.join(failReasons, StringPool.COMMA));
        //ythResult转换成json字符串
        return JSON.toJSONString(ythResult);
    }


    public void valueSet(List<RealPropertyFormVO> list) throws Exception{
        int i=1;
        List<PageData> orgList=orgzationDao.getGroupOrgList();
        Map<String,String> orgMap=orgList.stream().collect(Collectors.toMap(record->record.getString("orgCode"),record->record.getString("name")));
        for(RealPropertyFormVO r:list){
            r.setIndex(i++);
            String landMadeSituationStr="";
            String houseMadeSituationStr="";
            String isHaveRentAreaStr="否";
            String isHaveFairValueStr="否";
            Integer landMadeSituation=r.getLandMadeSituation();
            if(landMadeSituation!=null){
                if(landMadeSituation.intValue()==1){
                    landMadeSituationStr="已确权";
                }else if(landMadeSituation.intValue()==2){
                    landMadeSituationStr="未确权";
                }else if(landMadeSituation.intValue()==3){
                    landMadeSituationStr="部分确权";
                }
            }
            Integer houseMadeSituation=r.getHouseMadeSituation();
            if(houseMadeSituation!=null){
                if(houseMadeSituation.intValue()==1){
                    houseMadeSituationStr="已确权";
                }else if(houseMadeSituation.intValue()==2){
                    houseMadeSituationStr="未确权";
                }else if(houseMadeSituation.intValue()==3){
                    houseMadeSituationStr="部分确权";
                }
            }
            Integer isHaveRentArea=r.getIsHaveRentArea();
            if(isHaveRentArea!=null){
                if(isHaveRentArea.intValue()==2){
                    isHaveRentAreaStr="是";
                }else if(isHaveRentArea.intValue()==1){
                    isHaveRentAreaStr="否";
                }
            }
            Integer isHaveFairValue=r.getIsHaveFairValue();
            if(isHaveFairValue!=null){
                if(isHaveFairValue.intValue()==2){
                    isHaveFairValueStr="是";
                }else if(isHaveFairValue.intValue()==1){
                    isHaveFairValueStr="否";
                }
            }
            r.setLandMadeSituationName(landMadeSituationStr);
            r.setHouseMadeSituationName(houseMadeSituationStr);
            r.setIsHaveRentAreaName(isHaveRentAreaStr);
            r.setIsHaveFairValueName(isHaveFairValueStr);
            String orgCode=r.getOrgCode();
            //广电合并和城投合并节点单独处理
            if(orgCode.length()>8&&(orgCode.indexOf("00010106")!=-1||orgCode.indexOf("00010109")!=-1)){
                orgCode=orgCode.substring(0,10);
                String orgName=orgMap.get(orgCode);
                r.setFillingUnitName(orgName);
            }else if(orgCode.length()>=8){
                orgCode=orgCode.substring(0,8);
                String orgName=orgMap.get(orgCode);
                r.setFillingUnitName(orgName);
            }
        }
    }

    private RealProperty findLandByName(String landName){
        return getOne(new LambdaQueryWrapper<RealProperty>()
                .eq(RealProperty::getLandName, landName)
                .eq(RealProperty::getRealPropertyNature, 1)
                .eq(RealProperty::getFormType, String.valueOf(FormTypeConstant.PM_REAl_PROPERTY))
                .in(RealProperty::getStatus, Stream.of(-1,0,2).collect(Collectors.toList())));
    }

    private RealProperty findHouseByName(String houseName){
        return getOne(new LambdaQueryWrapper<RealProperty>()
                .eq(RealProperty::getHouseName, houseName)
                .eq(RealProperty::getRealPropertyNature, 2)
                .eq(RealProperty::getFormType, String.valueOf(FormTypeConstant.PM_REAl_PROPERTY))
                .in(RealProperty::getStatus, Stream.of(-1,0,2).collect(Collectors.toList())));
    }

    private Map<String, Map<String, String>> getRef() {
        Map<String, Map<String, String>> mapRefs = new HashMap<>(16);
        mapRefs.put("landTypeRef", baseInfoService.getChildMap(LAND_TYPE));
        mapRefs.put("landUsedRef", baseInfoService.getChildMap(ValueSetConstant.LAND_USED));
        mapRefs.put("estatePlanningRef", baseInfoService.getChildMap(ValueSetConstant.ESTATE_PLANNING));
        mapRefs.put("estateSourceRef", baseInfoService.getChildMap(ValueSetConstant.ESTATE_SOURCE));
        mapRefs.put("estateRealRef", baseInfoService.getChildMap(ValueSetConstant.ESTATE_REAL));
        mapRefs.put("buildingStructureRef", baseInfoService.getChildMap(BUILDING_STRUCTURE));

        return mapRefs;
    }


    private ImportResult checkLandData(Map<String, Map<String, String>> mapRef, List<Object> readExcels,
                                   String progressId, List<String> existLandNames,List<PageData> allOrg,
                                       Map<String, PageData> orgNameMap) {
        ImportResult importResult = new ImportResult(true, "");

        StringBuilder msg = new StringBuilder();
        String sheetNo = "2";
        if (CollectionUtil.isNotEmpty(readExcels)) {
            for (Object readExcel : readExcels) {
                LandInfoExcelBean excelBean = (LandInfoExcelBean) readExcel;
                int index = readExcels.indexOf(readExcel);

                //判空
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "归属单位",
                        excelBean.getOrgName(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "归属集团",
                        excelBean.getOrgGrpName(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "地块名称",
                        excelBean.getLandName(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "坐落位置",
                        excelBean.getLandLocatedPosition(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "土地性质",
                        excelBean.getLandNature(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "土地总面积(m²)",
                        excelBean.getLandTotalArea(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "土地用途",
                        excelBean.getLandUse(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "土地入账价值",
                        excelBean.getLandBookValue(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "确权情况",
                        excelBean.getLandMadeSituation(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "已确权面积",
                        excelBean.getLandMadeArea(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "未确权面积",
                        excelBean.getLandNoMadeArea(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "是否出租",
                        excelBean.getIsHaveRentArea(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "是否每年公允值入账",
                        excelBean.getIsHaveFairValue(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "目前资产用途",
                        excelBean.getCurrAssetUsage(), index).getMsg());
                if("2".equals(excelBean.getIsHaveRentArea())){
                    msg.append(ImportExcelUtil.checkEmpty(sheetNo, "可出租面积",
                            excelBean.getCanRentArea(), index).getMsg());
                    msg.append(ImportExcelUtil.checkEmpty(sheetNo, "已出租面积",
                            excelBean.getHaveRentArea(), index).getMsg());
                    msg.append(ImportExcelUtil.checkEmpty(sheetNo, "收取租金",
                            excelBean.getAcceptRent(), index).getMsg());
                    msg.append(ImportExcelUtil.checkEmpty(sheetNo, "出租年限",
                            excelBean.getRentDuration(), index).getMsg());
                }


                //类型判断
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_DATE, sheetNo, "土地取得时间",
                        excelBean.getLandAcquisitionTime(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_DATE, sheetNo, "发证日期",
                        excelBean.getLandReleaseDate(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_INTEGER, sheetNo, "确权情况",
                        excelBean.getLandMadeSituation(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_BIGDECIMAL, sheetNo, "土地总面积(m²)",
                        excelBean.getLandTotalArea(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_BIGDECIMAL, sheetNo, "土地入账价值",
                        excelBean.getLandBookValue(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_BIGDECIMAL, sheetNo, "已确权面积",
                        excelBean.getLandMadeArea(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_BIGDECIMAL, sheetNo, "未确权面积",
                        excelBean.getLandNoMadeArea(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_INTEGER, sheetNo, "是否出租",
                        excelBean.getIsHaveRentArea(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_INTEGER, sheetNo, "是否每年公允值入账",
                        excelBean.getIsHaveFairValue(), index).getMsg());
                if("2".equals(excelBean.getIsHaveRentArea())){
                    msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_BIGDECIMAL, sheetNo, "可出租面积",
                            excelBean.getCanRentArea(), index).getMsg());
                    msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_BIGDECIMAL, sheetNo, "已出租面积",
                            excelBean.getHaveRentArea(), index).getMsg());
                    msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_BIGDECIMAL, sheetNo, "收取租金",
                            excelBean.getAcceptRent(), index).getMsg());
                    msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_INTEGER, sheetNo, "出租年限",
                            excelBean.getRentDuration(), index).getMsg());
                }

            }
            //判断完类型若有错直接返回
            if (msg.toString().length() > 0) {
                return new ImportResult(false, msg.toString());
            }

            // 获取所有组织名称set、map
            Set<String> orgNameSet = allOrg.stream().map(obj -> obj.getString("orgName")).collect(Collectors.toSet());

            //对象和字典是否存在校验
            int size = readExcels.size();
            int count = 0;
            for (Object readExcel : readExcels) {
                LandInfoExcelBean excelBean = (LandInfoExcelBean) readExcel;
                int index = readExcels.indexOf(readExcel);

                if (StringUtil.isNotBlank(excelBean.getOrgName())){
                    if (!orgNameSet.contains(excelBean.getOrgName())){
                        msg.append("sheet2第" + index + "行(归属单位=" + excelBean.getOrgName() + ") 在系统中不存在\n");
                    }
                }

                if (StringUtil.isNotBlank(excelBean.getOrgGrpName())){
                    if (!orgNameSet.contains(excelBean.getOrgGrpName())){
                        msg.append("sheet2第" + index + "行(归属集团=" + excelBean.getOrgGrpName() + ") 在系统中不存在\n");
                    }
                }

                if(orgNameSet.contains(excelBean.getOrgName()) &&
                        orgNameSet.contains(excelBean.getOrgGrpName())){
                    PageData org = orgNameMap.get(excelBean.getOrgName());
                    PageData orgGrp = orgzationService.getOrgUnit(org, allOrg);
                    if(null == orgGrp){
                        msg.append("sheet2第" + index + "行(归属单位=" + excelBean.getOrgName() + ") 的归属集团不存在\n");
                    }else if(!excelBean.getOrgGrpName().equals(orgGrp.getString("orgName"))){
                        msg.append("sheet2第" + index + "行(归属集团=" + excelBean.getOrgGrpName() + ") 与系统中的归属集团="+orgGrp.getString("orgName")+"不一致\n");
                    }
                }

                if (StringUtil.isNotBlank(excelBean.getLandName())){
                    if (existLandNames.contains(excelBean.getLandName())){
                        msg.append("sheet2第" + index + "行(土地名称=" + excelBean.getLandName() + ") 在系统中已存在\n");
                    }
                }

                //土地性质
                if (StringUtil.isNotBlank(excelBean.getLandNature())) {
                    if (!mapRef.get("landTypeRef").containsKey(excelBean.getLandNature())) {
                        msg.append("sheet2第" + index + "行(土地性质=" + excelBean.getLandNature() + ")在系统中不存在\n");
                    }
                }

                //土地用途
                if (StringUtil.isNotBlank(excelBean.getLandUse())) {
                    if (!mapRef.get("landUsedRef").containsKey(excelBean.getLandUse())) {
                        msg.append("sheet2第" + index + "行(土地用途=" + excelBean.getLandUse() + ")在系统中不存在\n");
                    }
                }

                if (StringUtil.isNotBlank(excelBean.getLandMadeSituation())) {
                    if (!"1".equals(excelBean.getLandMadeSituation())
                            && !"2".equals(excelBean.getLandMadeSituation())
                            && ! "3".equals(excelBean.getLandMadeSituation())) {
                        msg.append("sheet2第" + index + "行(确权情况=" + excelBean.getLandMadeSituation() + ") 不是1、2、3\n");
                    }
                }

                if (StringUtil.isNotBlank(excelBean.getIsHaveRentArea())) {
                    if (!"1".equals(excelBean.getIsHaveRentArea())
                            && !"2".equals(excelBean.getIsHaveRentArea())) {
                        msg.append("sheet2第" + index + "行(是否出租=" + excelBean.getIsHaveRentArea() + ") 不是1或者2\n");
                    }
                }

                if (StringUtil.isNotBlank(excelBean.getIsHaveFairValue())) {
                    if (!"1".equals(excelBean.getIsHaveFairValue())
                            && !"2".equals(excelBean.getIsHaveFairValue())) {
                        msg.append("sheet2第" + index + "行(是否每年公允值入账=" + excelBean.getIsHaveFairValue() + ") 不是1或者2\n");
                    }
                }


                count++;
                int value = count * 100 / size;
                CacheUtil.put("progress", "progress", progressId, value);
            }
        }

        //统一放置报错
        if (msg.toString().length() > 0) {
            importResult = new ImportResult(false, msg.toString());
        }

        return importResult;

    }

    private ImportResult checkHouseData(Map<String, Map<String, String>> mapRef, List<Object> readExcels,
                                       String progressId, List<String> existLandNames,List<PageData> allOrg,
                                        Map<String, PageData> orgNameMap) {
        ImportResult importResult = new ImportResult(true, "");

        StringBuilder msg = new StringBuilder();
        String sheetNo = "3";

        if (CollectionUtil.isNotEmpty(readExcels)) {
            for (Object readExcel : readExcels) {
                HouseInfoExcelBean excelBean = (HouseInfoExcelBean) readExcel;
                int index = readExcels.indexOf(readExcel);;

                //判空
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "归属单位",
                        excelBean.getOrgName(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "归属集团",
                        excelBean.getOrgGrpName(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "房产名称",
                        excelBean.getHouseName(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "房产地址",
                        excelBean.getHouseLocatedPosition(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "房产性质",
                        excelBean.getHouseNature(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "房产总面积(m²)",
                        excelBean.getHouseTotalArea(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "房产入账价值",
                        excelBean.getHouseBookValue(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "房产确权情况",
                        excelBean.getHouseMadeSituation(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "房产已确权面积",
                        excelBean.getHouseMadeArea(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "房产未确权面积",
                        excelBean.getHouseNoMadeArea(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "是否出租",
                        excelBean.getIsHaveRentArea(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "是否每年公允值入账",
                        excelBean.getIsHaveFairValue(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "目前资产用途",
                        excelBean.getCurrAssetUsage(), index).getMsg());
                if("2".equals(excelBean.getIsHaveRentArea())){
                    msg.append(ImportExcelUtil.checkEmpty(sheetNo, "可出租面积",
                            excelBean.getCanRentArea(), index).getMsg());
                    msg.append(ImportExcelUtil.checkEmpty(sheetNo, "已出租面积",
                            excelBean.getHaveRentArea(), index).getMsg());
                    msg.append(ImportExcelUtil.checkEmpty(sheetNo, "收取租金",
                            excelBean.getAcceptRent(), index).getMsg());
                    msg.append(ImportExcelUtil.checkEmpty(sheetNo, "出租年限",
                            excelBean.getRentDuration(), index).getMsg());
                }


                //类型判断
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_DATE, sheetNo, "土地取得时间",
                        excelBean.getLandAcquisitionTime(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_DATE, sheetNo, "土地发证日期",
                        excelBean.getLandReleaseDate(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_INTEGER, sheetNo, "土地确权情况",
                        excelBean.getLandMadeSituation(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_BIGDECIMAL, sheetNo, "土地总面积(m²)",
                        excelBean.getLandTotalArea(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_BIGDECIMAL, sheetNo, "土地入账价值",
                        excelBean.getLandBookValue(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_BIGDECIMAL, sheetNo, "土地已确权面积",
                        excelBean.getLandMadeArea(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_BIGDECIMAL, sheetNo, "土地未确权面积",
                        excelBean.getLandNoMadeArea(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_DATE, sheetNo, "房产取得时间",
                        excelBean.getHouseReleaseDate(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_INTEGER, sheetNo, "房产确权情况",
                        excelBean.getHouseMadeSituation(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_INTEGER, sheetNo, "证件类型",
                        excelBean.getDocumentType(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_INTEGER, sheetNo, "车位数量",
                        excelBean.getParkingNumber(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_BIGDECIMAL, sheetNo, "房产总面积(m²)",
                        excelBean.getHouseTotalArea(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_BIGDECIMAL, sheetNo, "房产入账价值",
                        excelBean.getHouseBookValue(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_BIGDECIMAL, sheetNo, "房产已确权面积",
                        excelBean.getHouseMadeArea(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_BIGDECIMAL, sheetNo, "房产未确权面积",
                        excelBean.getHouseNoMadeArea(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_INTEGER, sheetNo, "是否出租",
                        excelBean.getIsHaveRentArea(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_INTEGER, sheetNo, "是否每年公允值入账",
                        excelBean.getIsHaveFairValue(), index).getMsg());
                if("2".equals(excelBean.getIsHaveRentArea())){
                    msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_BIGDECIMAL, sheetNo, "可出租面积",
                            excelBean.getCanRentArea(), index).getMsg());
                    msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_BIGDECIMAL, sheetNo, "已出租面积",
                            excelBean.getHaveRentArea(), index).getMsg());
                    msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_BIGDECIMAL, sheetNo, "收取租金",
                            excelBean.getAcceptRent(), index).getMsg());
                    msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_INTEGER, sheetNo, "出租年限",
                            excelBean.getRentDuration(), index).getMsg());
                }


            }
            //判断完类型若有错直接返回
            if (msg.toString().length() > 0) {
                return new ImportResult(false, msg.toString());
            }

            // 获取所有组织名称set、map
            Set<String> orgNameSet = allOrg.stream().map(obj -> obj.getString("orgName")).collect(Collectors.toSet());

            //对象和字典是否存在校验
            int size = readExcels.size();
            int count = 0;
            for (Object readExcel : readExcels) {
                HouseInfoExcelBean excelBean = (HouseInfoExcelBean) readExcel;
                int index = readExcels.indexOf(readExcel);

                if (StringUtil.isNotBlank(excelBean.getOrgName())){
                    if (!orgNameSet.contains(excelBean.getOrgName())){
                        msg.append("sheet2第" + index + "行(归属单位=" + excelBean.getOrgName() + ") 在系统中不存在\n");
                    }
                }

                if (StringUtil.isNotBlank(excelBean.getOrgGrpName())){
                    if (!orgNameSet.contains(excelBean.getOrgGrpName())){
                        msg.append("sheet2第" + index + "行(归属集团=" + excelBean.getOrgGrpName() + ") 在系统中不存在\n");
                    }
                }

                if(orgNameSet.contains(excelBean.getOrgName()) &&
                        orgNameSet.contains(excelBean.getOrgGrpName())){
                    PageData org = orgNameMap.get(excelBean.getOrgName());
                    PageData orgGrp = orgzationService.getOrgUnit(org, allOrg);
                    if(null == orgGrp){
                        msg.append("sheet2第" + index + "行(归属单位=" + excelBean.getOrgName() + ") 的归属集团不存在\n");
                    }else if(!excelBean.getOrgGrpName().equals(orgGrp.getString("orgName"))){
                        msg.append("sheet2第" + index + "行(归属集团=" + excelBean.getOrgGrpName() + ") 与系统中的归属集团="+orgGrp.getString("orgName")+"不一致\n");
                    }
                }

                if (StringUtil.isNotBlank(excelBean.getHouseName())){
                    if (existLandNames.contains(excelBean.getHouseName())){
                        msg.append("sheet2第" + index + "行(房产名称="
                                + excelBean.getHouseName() +") 在系统中已存在\n");
                    }
                }

                //土地性质
                if (StringUtil.isNotBlank(excelBean.getLandNature())) {
                    if (!mapRef.get("landTypeRef").containsKey(excelBean.getLandNature())) {
                        msg.append("sheet2第" + index + "行(土地性质=" + excelBean.getLandNature() + ")在系统中不存在\n");
                    }
                }

                //土地用途
                if (StringUtil.isNotBlank(excelBean.getLandUse())) {
                    if (!mapRef.get("landUsedRef").containsKey(excelBean.getLandUse())) {
                        msg.append("sheet2第" + index + "行(土地用途=" + excelBean.getLandUse() + ")在系统中不存在\n");
                    }
                }

                if (StringUtil.isNotBlank(excelBean.getLandMadeSituation())) {
                    if (!"1".equals(excelBean.getLandMadeSituation())
                            && ! "2".equals(excelBean.getLandMadeSituation())
                            && ! "3".equals(excelBean.getLandMadeSituation())) {
                        msg.append("sheet2第" + index + "行(土地确权情况=" + excelBean.getLandMadeSituation() + ") 不是1、2、3\n");
                    }
                }

                //房屋结构
                if (StringUtil.isNotBlank(excelBean.getHouseStructure())) {
                    if (!mapRef.get("buildingStructureRef").containsKey(excelBean.getHouseStructure())) {
                        msg.append("sheet2第" + index + "行(房屋结构=" + excelBean.getHouseStructure() + ")在系统中不存在\n");
                    }
                }


                //房产性质
                if (StringUtil.isNotBlank(excelBean.getHouseNature())) {
                    if (!mapRef.get("estateRealRef").containsKey(excelBean.getHouseNature())) {
                        msg.append("sheet2第" + index + "行(房产性质=" + excelBean.getHouseNature() + ")在系统中不存在\n");
                    }
                }

                //房产来源
                if (StringUtil.isNotBlank(excelBean.getHouseSource())) {
                    if (!mapRef.get("estateSourceRef").containsKey(excelBean.getHouseSource())) {
                        msg.append("sheet2第" + index + "行(房产来源=" + excelBean.getHouseSource() + ")在系统中不存在\n");
                    }
                }
                //房产规划用途
                if (StringUtil.isNotBlank(excelBean.getHouseUse())) {
                    if (!mapRef.get("estatePlanningRef").containsKey(excelBean.getHouseUse())) {
                        msg.append("sheet2第" + index + "行(房产规划用途=" + excelBean.getHouseUse() + ")在系统中不存在\n");
                    }
                }
                if (StringUtil.isNotBlank(excelBean.getHouseMadeSituation())) {
                    if (!"1".equals(excelBean.getHouseMadeSituation())
                            && ! "2".equals(excelBean.getHouseMadeSituation())
                            && ! "3".equals(excelBean.getHouseMadeSituation())) {
                        msg.append("sheet2第" + index + "行(房产确权情况=" + excelBean.getHouseMadeSituation() + ") 不是1、2、3\n");
                    }
                }

                if (StringUtil.isNotBlank(excelBean.getDocumentType())) {
                    if (!"1".equals(excelBean.getDocumentType())
                            && !"2".equals(excelBean.getDocumentType())) {
                        msg.append("sheet2第" + index + "行(证件类型=" + excelBean.getDocumentType() + ") 不是1或者2\n");
                    }
                }


                if (StringUtil.isNotBlank(excelBean.getIsHaveRentArea())) {
                    if (!"1".equals(excelBean.getIsHaveRentArea())
                            && !"2".equals(excelBean.getIsHaveRentArea())) {
                        msg.append("sheet2第" + index + "行(是否出租=" + excelBean.getIsHaveRentArea() + ") 不是1或者2\n");
                    }
                }

                if (StringUtil.isNotBlank(excelBean.getIsHaveFairValue())) {
                    if (!"1".equals(excelBean.getIsHaveFairValue())
                            && !"2".equals(excelBean.getIsHaveFairValue())) {
                        msg.append("sheet2第" + index + "行(是否每年公允值入账=" + excelBean.getIsHaveFairValue() + ") 不是1或者2\n");
                    }
                }


                count++;
                int value = count * 100 / size;
                CacheUtil.put("progress", "progress", progressId, value);
            }
        }

        //统一放置报错
        if (msg.toString().length() > 0) {
            importResult = new ImportResult(false, msg.toString());
        }

        return importResult;

    }

    private ImportResult checkEstateData(Map<String, Map<String, String>> mapRef, List<Object> readExcels,
                                        String progressId, List<String> existLandNames,List<PageData> allOrg,
                                         Map<String, PageData> orgNameMap) {
        ImportResult importResult = new ImportResult(true, "");

        StringBuilder msg = new StringBuilder();
        String sheetNo = "4";

        if (CollectionUtil.isNotEmpty(readExcels)) {
            for (Object readExcel : readExcels) {
                EstateInfoExcelBean excelBean = (EstateInfoExcelBean) readExcel;
                int index = readExcels.indexOf(readExcel);;

                //判空
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "归属单位",
                        excelBean.getOrgName(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "归属集团",
                        excelBean.getOrgGrpName(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "地块名称",
                        excelBean.getLandName(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "坐落位置",
                        excelBean.getLandLocatedPosition(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "土地性质",
                        excelBean.getLandNature(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "土地总面积(m²)",
                        excelBean.getLandTotalArea(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "土地用途",
                        excelBean.getLandUse(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "土地入账价值",
                        excelBean.getLandBookValue(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "确权情况",
                        excelBean.getLandMadeSituation(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "已确权面积",
                        excelBean.getLandMadeArea(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "未确权面积",
                        excelBean.getLandNoMadeArea(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "房产名称",
                        excelBean.getHouseName(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "房产地址",
                        excelBean.getHouseLocatedPosition(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "房产性质",
                        excelBean.getHouseNature(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "房产总面积(m²)",
                        excelBean.getHouseTotalArea(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "房产入账价值",
                        excelBean.getHouseBookValue(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "房产确权情况",
                        excelBean.getHouseMadeSituation(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "房产已确权面积",
                        excelBean.getHouseMadeArea(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "房产未确权面积",
                        excelBean.getHouseNoMadeArea(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "是否出租",
                        excelBean.getIsHaveRentArea(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "是否每年公允值入账",
                        excelBean.getIsHaveFairValue(), index).getMsg());
                msg.append(ImportExcelUtil.checkEmpty(sheetNo, "目前资产用途",
                        excelBean.getCurrAssetUsage(), index).getMsg());
                if("2".equals(excelBean.getIsHaveRentArea())){
                    msg.append(ImportExcelUtil.checkEmpty(sheetNo, "可出租面积",
                            excelBean.getCanRentArea(), index).getMsg());
                    msg.append(ImportExcelUtil.checkEmpty(sheetNo, "已出租面积",
                            excelBean.getHaveRentArea(), index).getMsg());
                    msg.append(ImportExcelUtil.checkEmpty(sheetNo, "收取租金",
                            excelBean.getAcceptRent(), index).getMsg());
                    msg.append(ImportExcelUtil.checkEmpty(sheetNo, "出租年限",
                            excelBean.getRentDuration(), index).getMsg());
                }

                //类型判断
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_DATE, sheetNo, "土地取得时间",
                        excelBean.getLandAcquisitionTime(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_DATE, sheetNo, "土地发证日期",
                        excelBean.getLandReleaseDate(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_INTEGER, sheetNo, "土地确权情况",
                        excelBean.getLandMadeSituation(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_BIGDECIMAL, sheetNo, "土地总面积(m²)",
                        excelBean.getLandTotalArea(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_BIGDECIMAL, sheetNo, "土地入账价值",
                        excelBean.getLandBookValue(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_BIGDECIMAL, sheetNo, "土地已确权面积",
                        excelBean.getLandMadeArea(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_BIGDECIMAL, sheetNo, "土地未确权面积",
                        excelBean.getLandNoMadeArea(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_DATE, sheetNo, "房产取得时间",
                        excelBean.getHouseReleaseDate(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_INTEGER, sheetNo, "房产确权情况",
                        excelBean.getHouseMadeSituation(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_INTEGER, sheetNo, "证件类型",
                        excelBean.getDocumentType(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_INTEGER, sheetNo, "车位数量",
                        excelBean.getParkingNumber(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_BIGDECIMAL, sheetNo, "房产总面积(m²)",
                        excelBean.getHouseTotalArea(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_BIGDECIMAL, sheetNo, "房产入账价值",
                        excelBean.getHouseBookValue(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_BIGDECIMAL, sheetNo, "房产已确权面积",
                        excelBean.getHouseMadeArea(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_BIGDECIMAL, sheetNo, "房产未确权面积",
                        excelBean.getHouseNoMadeArea(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_INTEGER, sheetNo, "是否出租",
                        excelBean.getIsHaveRentArea(), index).getMsg());
                msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_INTEGER, sheetNo, "是否每年公允值入账",
                        excelBean.getIsHaveFairValue(), index).getMsg());
                if("2".equals(excelBean.getIsHaveRentArea())){
                    msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_BIGDECIMAL, sheetNo, "可出租面积",
                            excelBean.getCanRentArea(), index).getMsg());
                    msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_BIGDECIMAL, sheetNo, "已出租面积",
                            excelBean.getHaveRentArea(), index).getMsg());
                    msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_BIGDECIMAL, sheetNo, "收取租金",
                            excelBean.getAcceptRent(), index).getMsg());
                    msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_INTEGER, sheetNo, "出租年限",
                            excelBean.getRentDuration(), index).getMsg());
                }


            }
            //判断完类型若有错直接返回
            if (msg.toString().length() > 0) {
                return new ImportResult(false, msg.toString());
            }
            // 获取所有组织名称set、map
            Set<String> orgNameSet = allOrg.stream().map(obj -> obj.getString("orgName")).collect(Collectors.toSet());

            //对象和字典是否存在校验
            int size = readExcels.size();
            int count = 0;
            for (Object readExcel : readExcels) {
                EstateInfoExcelBean excelBean = (EstateInfoExcelBean) readExcel;
                int index = readExcels.indexOf(readExcel);

                if (StringUtil.isNotBlank(excelBean.getOrgName())){
                    if (!orgNameSet.contains(excelBean.getOrgName())){
                        msg.append("sheet2第" + index + "行(归属单位=" + excelBean.getOrgName() + ") 在系统中不存在\n");
                    }
                }

                if (StringUtil.isNotBlank(excelBean.getOrgGrpName())){
                    if (!orgNameSet.contains(excelBean.getOrgGrpName())){
                        msg.append("sheet2第" + index + "行(归属集团=" + excelBean.getOrgGrpName() + ") 在系统中不存在\n");
                    }
                }

                if(orgNameSet.contains(excelBean.getOrgName()) &&
                        orgNameSet.contains(excelBean.getOrgGrpName())){
                    PageData org = orgNameMap.get(excelBean.getOrgName());
                    PageData orgGrp = orgzationService.getOrgUnit(org, allOrg);
                    if(null == orgGrp){
                        msg.append("sheet2第" + index + "行(归属单位=" + excelBean.getOrgName() + ") 的归属集团不存在\n");
                    }else if(!excelBean.getOrgGrpName().equals(orgGrp.getString("orgName"))){
                        msg.append("sheet2第" + index + "行(归属集团=" + excelBean.getOrgGrpName() + ") 与系统中的归属集团="+orgGrp.getString("orgName")+"不一致\n");
                    }
                }

                if (StringUtil.isNotBlank(excelBean.getLandName())){
                    if (existLandNames.contains(excelBean.getLandName())){
                        msg.append("sheet2第" + index + "行(土地名称=" + excelBean.getLandName() + ") 在系统中已存在\n");
                    }
                }

                //土地性质
                if (StringUtil.isNotBlank(excelBean.getLandNature())) {
                    if (!mapRef.get("landTypeRef").containsKey(excelBean.getLandNature())) {
                        msg.append("sheet2第" + index + "行(土地性质=" + excelBean.getLandNature() + ")在系统中不存在\n");
                    }
                }

                //土地用途
                if (StringUtil.isNotBlank(excelBean.getLandUse())) {
                    if (!mapRef.get("landUsedRef").containsKey(excelBean.getLandUse())) {
                        msg.append("sheet2第" + index + "行(土地用途=" + excelBean.getLandUse() + ")在系统中不存在\n");
                    }
                }

                if (StringUtil.isNotBlank(excelBean.getLandMadeSituation())) {
                    if (!"1".equals(excelBean.getLandMadeSituation())
                            && !"2".equals(excelBean.getLandMadeSituation())
                            && ! "3".equals(excelBean.getLandMadeSituation())) {
                        msg.append("sheet2第" + index + "行(确权情况=" + excelBean.getLandMadeSituation() + ") 不是1、2、3\n");
                    }
                }


                if (StringUtil.isNotBlank(excelBean.getHouseName())){
                    if (existLandNames.contains(excelBean.getHouseName())){
                        msg.append("sheet2第" + index + "行(房产名称="
                                + excelBean.getHouseName() +") 在系统中已存在\n");
                    }
                }

                //土地性质
                if (StringUtil.isNotBlank(excelBean.getLandNature())) {
                    if (!mapRef.get("landTypeRef").containsKey(excelBean.getLandNature())) {
                        msg.append("sheet2第" + index + "行(土地性质=" + excelBean.getLandNature() + ")在系统中不存在\n");
                    }
                }

                //土地用途
                if (StringUtil.isNotBlank(excelBean.getLandUse())) {
                    if (!mapRef.get("landUsedRef").containsKey(excelBean.getLandUse())) {
                        msg.append("sheet2第" + index + "行(土地用途=" + excelBean.getLandUse() + ")在系统中不存在\n");
                    }
                }

                if (StringUtil.isNotBlank(excelBean.getLandMadeSituation())) {
                    if (!"1".equals(excelBean.getLandMadeSituation())
                            && ! "2".equals(excelBean.getLandMadeSituation())
                            && ! "3".equals(excelBean.getLandMadeSituation())) {
                        msg.append("sheet2第" + index + "行(土地确权情况=" + excelBean.getLandMadeSituation() + ") 不是1、2、3\n");
                    }
                }

                //房屋结构
                if (StringUtil.isNotBlank(excelBean.getHouseStructure())) {
                    if (!mapRef.get("buildingStructureRef").containsKey(excelBean.getHouseStructure())) {
                        msg.append("sheet2第" + index + "行(房屋结构=" + excelBean.getHouseStructure() + ")在系统中不存在\n");
                    }
                }


                //房产性质
                if (StringUtil.isNotBlank(excelBean.getHouseNature())) {
                    if (!mapRef.get("estateRealRef").containsKey(excelBean.getHouseNature())) {
                        msg.append("sheet2第" + index + "行(房产性质=" + excelBean.getHouseNature() + ")在系统中不存在\n");
                    }
                }

                //房产来源
                if (StringUtil.isNotBlank(excelBean.getHouseSource())) {
                    if (!mapRef.get("estateSourceRef").containsKey(excelBean.getHouseSource())) {
                        msg.append("sheet2第" + index + "行(房产来源=" + excelBean.getHouseSource() + ")在系统中不存在\n");
                    }
                }
                //房产规划用途
                if (StringUtil.isNotBlank(excelBean.getHouseUse())) {
                    if (!mapRef.get("estatePlanningRef").containsKey(excelBean.getHouseUse())) {
                        msg.append("sheet2第" + index + "行(房产规划用途=" + excelBean.getHouseUse() + ")在系统中不存在\n");
                    }
                }
                if (StringUtil.isNotBlank(excelBean.getHouseMadeSituation())) {
                    if (!"1".equals(excelBean.getHouseMadeSituation())
                            && ! "2".equals(excelBean.getHouseMadeSituation())
                            && ! "3".equals(excelBean.getHouseMadeSituation())) {
                        msg.append("sheet2第" + index + "行(房产确权情况=" + excelBean.getHouseMadeSituation() + ") 不是1、2、3\n");
                    }
                }

                if (StringUtil.isNotBlank(excelBean.getDocumentType())) {
                    if (!"1".equals(excelBean.getDocumentType())
                            && !"2".equals(excelBean.getDocumentType())) {
                        msg.append("sheet2第" + index + "行(证件类型=" + excelBean.getDocumentType() + ") 不是1或者2\n");
                    }
                }


                if (StringUtil.isNotBlank(excelBean.getIsHaveRentArea())) {
                    if (!"1".equals(excelBean.getIsHaveRentArea())
                            && !"2".equals(excelBean.getIsHaveRentArea())) {
                        msg.append("sheet2第" + index + "行(是否出租=" + excelBean.getIsHaveRentArea() + ") 不是1或者2\n");
                    }
                }

                if (StringUtil.isNotBlank(excelBean.getIsHaveFairValue())) {
                    if (!"1".equals(excelBean.getIsHaveFairValue())
                            && !"2".equals(excelBean.getIsHaveFairValue())) {
                        msg.append("sheet2第" + index + "行(是否每年公允值入账=" + excelBean.getIsHaveFairValue() + ") 不是1或者2\n");
                    }
                }


                count++;
                int value = count * 100 / size;
                CacheUtil.put("progress", "progress", progressId, value);
            }
        }

        //统一放置报错
        if (msg.toString().length() > 0) {
            importResult = new ImportResult(false, msg.toString());
        }

        return importResult;

    }

    /**
     * 统一处理状态机事件方法
     * @param id 主键
     * @param updateStatus 更新状态
     * @return boolean
     */
    private Boolean handleStatus(Long id, int updateStatus, String comment) {
        try {
            RealProperty realProperty = getById(id);
            realProperty.setStatus(updateStatus);
            if (YthConstant.DATA_NINGBO.equals(realProperty.getDataSource())){
                if (updateStatus == FormStatusConstant.FINISH || updateStatus == FormStatusConstant.REJECT){
                    ApprovalMessage approvalMessage = new ApprovalMessage();
                    approvalMessage.setDataSourceId(realProperty.getDataSourceId());
                    approvalMessage.setOpinion(comment);
                    approvalMessage.setIsApprove(updateStatus == FormStatusConstant.FINISH ? 2 : 1);
                    approvalMessage.setIsSend(1);
                    approvalMessage.setDataSourceType(YthConstant.DATA_NINGBO);
                    approvalMessage.setFilingUserName(UserCache.userIdToName(TokenUtil.getTokenUserId()));
                    approvalMessage.setFormType(Integer.valueOf(realProperty.getFormType()));
                    approvalMessage.setFilingCode(realProperty.getCode());
                    approvalMessageService.save(approvalMessage);
                }
            }
            updateById(realProperty);
            return true;
        } catch (Exception e) {
            log.error(ExceptionUtils.getFullStackTrace(e));
            return false;
        }
    }

    @Override
    public boolean submit(RealProperty realProperty) {
        if (!Optional.ofNullable(realProperty.getStatus()).isPresent()){
            realProperty.setStatus(UNREVIEWED);
        }

        boolean result = saveOrUpdate(realProperty);
        HashMap<String, Object> processVariable = new HashMap<>();
        formWorkflowService.startProcessAndSimulate(String.valueOf(realProperty.getId()),realProperty.getFormType(),processVariable);
        return result;
    }
}
